﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.XPath;
using System.Reflection;

namespace FTI.SP.LADM.EnhancedContentQueryWebPart.Exslt
{
    public sealed class ExsltCommon
    {
        // Fields
        private static ExsltCommon _Instance;

        // Methods
        private ExsltCommon()
        {
        }

        internal static XPathNodeIterator ExsltNodeListToXPathNodeIterator(ExsltNodeList list)
        {
            return (XPathNodeIterator)Activator.CreateInstance(typeof(XPathNodeIterator).Assembly.GetType("System.Xml.XPath.XPathArrayIterator"), BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, new object[] { list.innerList }, null);
        }

        public static string ObjectType(object value)
        {
            if (value is string)
            {
                return "string";
            }
            if (value is bool)
            {
                return "boolean";
            }
            if ((((value is double) || (value is short)) || ((value is ushort) || (value is int))) || (((value is uint) || (value is long)) || (((value is ulong) || (value is float)) || (value is decimal))))
            {
                return "number";
            }
            if (value is XPathNavigator)
            {
                return "RTF";
            }
            if (value is XPathNodeIterator)
            {
                return "node-set";
            }
            return "external";
        }

        // Properties
        public static ExsltCommon Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new ExsltCommon();
                }
                return _Instance;
            }
        }

    }
}
